<%@page contentType="text/html; charset=UTF-8" import="javax.naming.*,javax.sql.*,java.sql.*"%>
<%
  Connection conn = null;
  ResultSet rst = null;
  String strRst = "";

  try {
    if (request.getParameter("lookupName") != null && !request.getParameter("lookupName").trim().equals("")) {
      Context ctx = new InitialContext();
      Context envContext = (Context) ctx.lookup("java:comp/env/");
      DataSource ds = (DataSource) envContext.lookup(request.getParameter("lookupName"));
      conn = ds.getConnection();
      rst = conn.createStatement().executeQuery("select sysdate from dual");
      while(rst.next()){
        strRst = rst.getString(1);
      }
    }
%>
<html>
<head>
<title>TestConnPool</title>
</head>
<body bgcolor="#ffffff">
<form action="TestConnPool_param.jsp" method="POST">  LookUpName：
<input type="text" name="lookupName" size="50"/>
<br/>
<input type="submit" value="submit"/>
</form>
<%
  if (request.getParameter("lookupName") != null && !request.getParameter("lookupName").trim().equals("")) {
    if (conn != null) {
      out.println(request.getParameter("lookupName") + " use Connection Pool Successful<br/>");
      out.println("sysdate==>" + strRst);
    }
    if (conn == null) {
      out.println(request.getParameter("lookupName") + " use Connection Pool fail");
    }
  }
%>
</body>
</html>
<%
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  finally {
    if (rst != null) {
      try {
        rst.getStatement().close();
        rst.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (conn != null) {
      try {
        conn.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      conn = null;
    }
  }
%>
